import java.util.Arrays;
import java.util.Random;

public class Test {

    public static void orderArray(int[] array) {
        for (int i = 0; i < array.length; i++) {
            array[i] = i;
        }
    }

    public static void notOrderArray(int[] array) {
        for (int i = 0; i < array.length; i++) {
            array[i] = array.length - i;
        }
    }

    public static void notOrderArrayRandom(int[] array) {
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(10_0000);
        }
    }

    public static void testInsertSort(int[] array) {
        int[] tmpArray = Arrays.copyOf(array, array.length);
        long startTime = System.currentTimeMillis();
        Sort.insertSort(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("插入排序耗时: " + (endTime - startTime) + " ms");
    }

    public static void testShellSort(int[] array) {
        int[] tmpArray = Arrays.copyOf(array, array.length);

        long startTime = System.currentTimeMillis();
        Sort.shellSort(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("希尔排序耗时: " + (endTime - startTime) + " ms");
    }

    public static void testSelectSort(int[] array) {
        int[] tmpArray = Arrays.copyOf(array, array.length);

        long startTime = System.currentTimeMillis();
        Sort.selectSort(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("选择排序耗时: " + (endTime - startTime) + " ms");
    }

    public static void testHeapSort(int[] array) {
        int[] tmpArray = Arrays.copyOf(array, array.length);

        long startTime = System.currentTimeMillis();
        Sort.heapSort(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("堆排序耗时: " + (endTime - startTime) + " ms");
    }

    public static void testQuickSort(int[] array) {
        int[] tmpArray = Arrays.copyOf(array, array.length);

        long startTime = System.currentTimeMillis();
        Sort.quickSort(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("快速排序耗时: " + (endTime - startTime) + " ms");
    }

    public static void testMergeSort(int[] array) {
        int[] tmpArray = Arrays.copyOf(array, array.length);

        long startTime = System.currentTimeMillis();
        Sort.mergeSort(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("归并排序耗时: " + (endTime - startTime) + " ms");
    }

    public static void testMergeSortNor(int[] array) {
        int[] tmpArray = Arrays.copyOf(array, array.length);

        long startTime = System.currentTimeMillis();
        Sort.mergeSortNor(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("归并排序非递归耗时: " + (endTime - startTime) + " ms");

//        System.out.println(Arrays.toString(tmpArray));
    }

    public static void testSort(int[] array) {
        int[] tmpArray = Arrays.copyOf(array, array.length);

        long startTime = System.currentTimeMillis();
        Arrays.sort(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("库函数排序耗时: " + (endTime - startTime) + " ms");
    }

    public static void main1(String[] args) {
        int[] array = new int[10000_000];
//        notOrderArray(array);
//        orderArray(array);
        notOrderArrayRandom(array);

//        testInsertSort(array);
        testSort(array);
        testShellSort(array);
//        testSelectSort(array);
        testHeapSort(array);
        testQuickSort(array);
        testMergeSort(array);
        testMergeSortNor(array);

    }


    public static void main(String[] args) {
        int[] array = {2000000, 5, 1, 3, 0, 6, 8, 9, 4, 7, 6, 0, 9, 23, 43, 12, 432, 452, 23, 124};
//        Sort.shellSort(array);
//        int[] array = {2};

        Sort.countSort(array);
        System.out.println(Arrays.toString(array));
    }
}

//2,5,1,3,8,9,4,7,6,0

// 2,5,3,8,9,4,7,6,0